package com.sjd.storehouse.service;

import com.sjd.storehouse.entity.Center;
import com.sjd.storehouse.entity.Rent;
import org.apache.ibatis.jdbc.SQL;

public class SqlService {

    public String updateCenterByIdProvider(Center center) {
        SQL sql = new SQL();
        sql.UPDATE("center");
        if (center.getName() != null) {
            sql.SET("name = #{name}");
        }
        if (center.getSpec() != null) {
            sql.SET("spec = #{spec}");
        }
        if (center.getNum() != null) {
            sql.SET("num = #{num}");
        }
        if (center.getUnit() != null) {
            sql.SET("unit = #{unit}");
        }
        if (center.getDelFlag() != null) {
            sql.SET("del_flag = #{delFlag}");
        }
        sql.WHERE(" id = #{id}");
        return sql.toString();
    }

    public String updateAssistByIdProvider(Center assist) {
        SQL sql = new SQL();
        sql.UPDATE("assist");
        if (assist.getName() != null) {
            sql.SET("name = #{name}");
        }
        if (assist.getSpec() != null) {
            sql.SET("spec = #{spec}");
        }
        if (assist.getNum() != null) {
            sql.SET("num = #{num}");
        }
        if (assist.getUnit() != null) {
            sql.SET("unit = #{unit}");
        }
        if (assist.getDelFlag() != null) {
            sql.SET("del_flag = #{delFlag}");
        }
        if (assist.getKind() != null) {
            sql.SET("kind = #{kind}");
        }
        if (assist.getUsername() != null) {
            sql.SET("username = #{username}");
        }
        sql.WHERE(" id = #{id}");
        return sql.toString();
    }

    public String updateRentByIdProvider(Rent rent) {
        SQL sql = new SQL();
        sql.UPDATE("rent");
        if (rent.getName() != null) {
            sql.SET("assist_id = #{assistId}");
        }
        if (rent.getDelFlag() != null) {
            sql.SET("del_flag = #{delFlag}");
        }
        if (rent.getKind() != null) {
            sql.SET("kind = #{kind}");
        }
        if (rent.getUsername() != null) {
            sql.SET("username = #{username}");
        }
        sql.WHERE(" id = #{id}");
        return sql.toString();
    }

}
